set more off
local stick "C:\Users\Andy baker\OneDrive - University of Colorado at Boulder Office 365"
capture log close
log using "`stick'\My Documents\Research\Paper PID Experiment\Russia\JOP IRT Russia Results.log", text replace
use "`stick'\My Documents\Research\Paper PID Experiment\Russia\andy_baker (all english labels).dta", clear
svyset [weight=qvec]

*I. PARTY ID MEASURES
	*1: Working with the "party closeness" variable 
gen close=qb1b
replace close=0 if qb1a==2 | qb1a==7
replace close=. if qb1a==8
replace close=. if qb1b==7 | qb1b==8

label define pid 0 Independent 1 "United Russia" 2 "Communist Party of Russia" 3 "Liberal Democratic Party of Russia" 4 "Just Russia" 5 "Other Party" 7 "Hard to say" 8 "Refusal"
label values close pid 

xi, noomit: svy: proportion i.close 

recode close (0=1) (.=.) (else=0), gen(close_indep)
recode close (1=1) (.=.) (else=0), gen(close_ur)
recode close (2=1) (.=.) (else=0), gen(close_comm)
recode close (3=1) (.=.) (else=0), gen(close_LDPR)
recode close (4=1) (.=.) (else=0), gen(close_JR)
recode close (5=1) (.=.) (else=0), gen(close_other)

	*2: Working with the "preference--explicit" variable, treatment A
recode qb2a (.=.) (6=0) (7=0) (8=.), gen(prefexp)
label values prefexp pid

xi, noomit: svy: proportion i.prefexp

recode prefexp (0=1) (.=.) (else=0), gen(prefexp_indep)
recode prefexp (1=1) (.=.) (else=0), gen(prefexp_ur)
recode prefexp (2=1) (.=.) (else=0), gen(prefexp_comm)
recode prefexp (3=1) (.=.) (else=0), gen(prefexp_LDPR)
recode prefexp (4=1) (.=.) (else=0), gen(prefexp_JR)
recode prefexp (5=1) (.=.) (else=0), gen(prefexp_other)

	*3: Working with the "identity" variable, treatment B
recode qb2b (.=.) (6=0) (7=0) (8=.), gen(identity)
label values identity pid

xi, noomit: svy: proportion i.identity

recode identity (0=1) (.=.) (else=0), gen(identity_indep)
recode identity (1=1) (.=.) (else=0), gen(identity_ur)
recode identity (2=1) (.=.) (else=0), gen(identity_comm)
recode identity (3=1) (.=.) (else=0), gen(identity_LDPR)
recode identity (4=1) (.=.) (else=0), gen(identity_JR)
recode identity (5=1) (.=.) (else=0), gen(identity_other)

	*4: Working with the "preference--implicit" variable, treatment C
recode qb2c (.=.) (6=0) (7=0) (8=.), gen(prefimp)
label values prefimp pid

xi, noomit: svy: proportion i.prefimp

recode prefimp (0=1) (.=.) (else=0), gen(prefimp_indep)
recode prefimp (1=1) (.=.) (else=0), gen(prefimp_ur)
recode prefimp (2=1) (.=.) (else=0), gen(prefimp_comm)
recode prefimp (3=1) (.=.) (else=0), gen(prefimp_LDPR)
recode prefimp (4=1) (.=.) (else=0), gen(prefimp_JR)
recode prefimp (5=1) (.=.) (else=0), gen(prefimp_other)

*II. OTHER MEASURES RELATED TO PARTY ID
	*1: Party nonrejection
recode qb3b_1 (1=0) (else=1), gen(nonreject_ur)
replace nonreject_ur=. if qb3a==8

recode qb3b_2 (1=0) (else=1), gen(nonreject_comm)
replace nonreject_comm=. if qb3a==8

recode qb3b_3 (1=0) (else=1), gen(nonreject_LDPR)
replace nonreject_LDPR=. if qb3a==8

recode qb3b_4 (1=0) (else=1), gen(nonreject_JR)
replace nonreject_JR=. if qb3a==8

	*2: Feeling thermometers
recode qb4a (0/5=0) (6/15=1) (16/25=2) (26/35=3) (36/45=4) (46/55=5) (56/65=6) (66/75=7) (76/85=8) (86/95=9) (96/100=10) (else=.) , gen(ft_ur)
recode qb4b (0/5=0) (6/15=1) (16/25=2) (26/35=3) (36/45=4) (46/55=5) (56/65=6) (66/75=7) (76/85=8) (86/95=9) (96/100=10) (else=.) , gen(ft_comm)
recode qb4c (0/5=0) (6/15=1) (16/25=2) (26/35=3) (36/45=4) (46/55=5) (56/65=6) (66/75=7) (76/85=8) (86/95=9) (96/100=10) (else=.) , gen(ft_LDPR)

	*3: Duma vote
label define dumavote 1 "Green Alliance - People's Party (Oleg Mitvol)" 2 "Civic Platform (R.Shayhutdinov)" 3 "United Russia (Medvedev)" 4 "The Communist Party (KPRF) (Zyuganov)"  5 "Liberal Democratic Party of Russia (LDPR) (Vladimir Zhirinovsky)" 6 "Progress Party (A.Navalny)" 7 "Patriots of Russia (G.Semigin)" 8 "The Republican Party of Russia - Parnassus (Kasyanov)" 9 "Homeland (Rogozin)" 10 "Just Russia (Mironov)" 11 "Apple (Mitrokhin)" 12 "Others" 13 "Would not vote" 14 "Hard to say"
label values q27b dumavote

recode q27b (3=1) (.=.) (else=0), gen(dumavote_ur)
recode q27b (4=1) (.=.) (else=0), gen(dumavote_comm)
recode q27b (5=1) (.=.) (else=0), gen(dumavote_LDPR)

	*4: Pres vote (although not used because too retrospective)
label define presvote 1 "The Communist Party (KPRF) (Zyuganov)" 2 "Liberal Democratic Party of Russia (LDPR) (Vladimir Zhirinovsky)" 3 "Just Russia (Mironov)" 4 "Mikhail Prokhorov" 5 "United Russia (Vladimir Putin)" 8 "Spoiled" 9 "Don't remember"  
label values qd1b presvote

recode qd1b (5=1) (.=.) (else=0), gen(presvote_ur)
recode qd1b (1=1) (.=.) (else=0), gen(presvote_comm)
recode qd1b (2=1) (.=.) (else=0), gen(presvote_LDPR)

replace presvote_ur =. if qd1a==9
replace presvote_comm =. if qd1a==9
replace presvote_LDPR =. if qd1a==9

*III. Descriptives
egen pref_comm=rsum(prefexp_comm prefimp_comm)
replace pref_comm=. if prefexp_comm==. & prefimp_comm==.

summ prefexp_ur prefimp_ur identity_ur close_ur nonreject_ur dumavote_ur ft_ur prefexp_LDPR prefimp_LDPR identity_LDPR close_LDPR nonreject_LDPR dumavote_LDPR ft_LDPR 
summ pref_comm identity_comm close_comm dumavote_comm nonreject_comm ft_comm
svy: mean prefexp_ur 
estat sd

svy: mean prefimp_ur 
estat sd

svy: mean identity_ur 
estat sd

svy: mean close_ur 
estat sd

svy: mean nonreject_ur 
estat sd

svy: mean dumavote_ur 
estat sd

svy: mean ft_ur 
estat sd

svy: mean prefexp_LDPR 
estat sd

svy: mean prefimp_LDPR 
estat sd

svy: mean identity_LDPR 
estat sd

svy: mean close_LDPR 
estat sd

svy: mean nonreject_LDPR 
estat sd

svy: mean dumavote_LDPR 
estat sd

svy: mean ft_LDPR 
estat sd
 
*IV. Randomization Check
gen exp=1 if qb2a~=.
replace exp=2 if qb2b~=.
replace exp=3 if qb2c~=.
recode qs1 2=1 1=0
bysort exp: ci mean close_indep close_ur qs1 qs2 qrnp

*V: Factor Analysis check for unidimensionality
polychoricpca prefexp_ur close_ur dumavote_ur ft_ur 
polychoricpca prefimp_ur close_ur dumavote_ur ft_ur 
polychoricpca identity_ur close_ur dumavote_ur ft_ur

polychoricpca prefexp_LDPR close_LDPR dumavote_LDPR ft_LDPR 
polychoricpca prefimp_LDPR close_LDPR dumavote_LDPR ft_LDPR 
polychoricpca identity_LDPR close_LDPR dumavote_LDPR ft_LDPR

polychoricpca pref_comm close_comm dumavote_comm ft_comm 
polychoricpca identity_comm close_comm dumavote_comm ft_comm

*VI. Criterion-Validity check
egen preference=rmax(prefimp prefexp)
label values preference pid

gen pref_close_ur=.
replace pref_close_ur=2 if close_ur==1 
replace pref_close_ur=1 if preference==1 & close_indep==1
replace pref_close_ur=0 if preference==0 & close==0
replace pref_close_ur=. if pref_close==2 & preference~=1 & preference~=0

gen pref_close_LDPR=.
replace pref_close_LDPR=2 if close_LDPR==1 
replace pref_close_LDPR=1 if preference==3 & close_indep==1
replace pref_close_LDPR=0 if preference==0 & close==0
replace pref_close_LDPR=. if pref_close_LDPR==2 & preference~=3 & preference~=0

gen pref_close_comm=.
replace pref_close_comm=2 if close_comm==1 
replace pref_close_comm=1 if preference==2 & close_indep==1
replace pref_close_comm=0 if preference==0 & close==0
replace pref_close_comm=. if pref_close_comm==2 & preference~=2 & preference~=0

recode q27b 3=1 13/14=. .=. else=0, gen(dumavoteUR)
recode q27b 5=1 13/14=. .=. else=0, gen(dumavoteLDPR)
recode q27b 4=1 13/14=. .=. else=0, gen(dumavotecomm)
recode q40aa 9=. 1=4 2=3 3=2 4=1
recode q40ab 9=. 1=4 2=3 3=2 4=1

local i=0
while `i'<=2 {
svy: mean dumavoteUR if pref_close_ur==`i'
local i=`i'+1
}

*Putin approval
local i=0
while `i'<=2 {
svy: mean q40aa if pref_close_ur==`i'
local i=`i'+1
}

*Gov't approval
local i=0
while `i'<=2 {
svy: mean q40ab if pref_close_ur==`i'
local i=`i'+1
}

recode q5b 2=0
*Medvedev approval
local i=0
while `i'<=2 {
svy: mean q5b if pref_close_ur==`i'
local i=`i'+1
}

local i=0
while `i'<=2 {
svy: mean dumavoteLDPR if pref_close_LDPR==`i'
local i=`i'+1
}

local i=0
while `i'<=2 {
svy: mean dumavotecomm if pref_close_comm==`i'
local i=`i'+1
}


svy: mean dumavoteUR if pref_close_ur~=.
estat sd

svy: mean q40aa 
estat sd

svy: mean q40ab 
estat sd

svy: mean q5b
estat sd

svy: mean dumavoteLDPR if pref_close_LDPR~=.
estat sd

svy: mean dumavotecomm if pref_close_comm~=.
estat sd

capture label drop party1
label define party1 0 "Agreed nonpart's" 1 "Contested UR partisans" 2 "Agreed UR partisans"
label values pref_close_ur party1

capture label drop party2
label define party2 0 "Agreed nonpart's" 1 "Contested LDPR partisans" 2 "Agreed LDPR partisans"
label values pref_close_LDPR party2

capture label drop party3
label define party3 0 "Agreed nonpart's" 1 "Contested CPRF partisans" 2 "Agreed CPRF partisans"
label values pref_close_comm party3



separate dumavoteUR, by(pref_close_ur)
separate q40aa, by(pref_close_ur)
separate q40ab, by(pref_close_ur)
separate q5b, by(pref_close_ur)

	*bar graphs
graph bar (mean) dumavoteUR? [pweight=qvec], over(pref_close_ur, label(angle(0) labsize(small) alternate tick labgap(0)))  graphregion(color(white)) plotregion(lcolor(black)) ///
blabel(bar, format(%9.2f) size(small)) bar(1, color(white) lcolor(black)) bar(2, color(gs12)) bar(3, color(black)) title("1: Duma vote for UR") ytitle("") ylab(, labsize(small))  legend(off) nofill
graph save "`stick'\My Documents\Research\Paper PID Experiment\Russia\urgr1.gph", replace

graph bar (mean) q40aa? [pweight=qvec], over(pref_close_ur, label(angle(0) labsize(small) alternate tick labgap(0)))  graphregion(color(white)) plotregion(lcolor(black)) ///
blabel(bar, format(%9.2f) size(small)) bar(1, color(white) lcolor(black)) bar(2, color(gs12)) bar(3, color(black)) title("2: Putin job approval") exclude0 yscale(range(2(.5)4)) ytick(2 2.5 3 3.5 4) ylab(2 2.5 3 3.5 4) ytitle("") ylab(, labsize(small))  legend(off) nofill 
graph save "`stick'\My Documents\Research\Paper PID Experiment\Russia\urgr2.gph", replace

graph bar (mean) q40ab? [pweight=qvec], over(pref_close_ur, label(angle(0) labsize(small) alternate tick labgap(0)))  graphregion(color(white)) plotregion(lcolor(black)) ///
blabel(bar, format(%9.2f) size(small)) bar(1, color(white) lcolor(black)) bar(2, color(gs12)) bar(3, color(black)) title("3: Government approval") exclude0 yscale(range(2(.5)4)) ytick(2 2.5 3 3.5 4) ylab(2 2.5 3 3.5 4) ytitle("") ylab(, labsize(small))  legend(off) nofill 
graph save "`stick'\My Documents\Research\Paper PID Experiment\Russia\urgr3.gph", replace

graph bar (mean) q5b? [pweight=qvec], over(pref_close_ur, label(angle(0) labsize(small) alternate  tick labgap(0)))  graphregion(color(white)) plotregion(lcolor(black)) ///
blabel(bar, format(%9.2f) size(small)) bar(1, color(white) lcolor(black)) bar(2, color(gs12)) bar(3, color(black)) title("4: Medvedev job approval") yscale(range(0(.2)1)) ytick(0 .2 .4 .6 .8 1) ylab(0 .2 .4 .6 .8 1) ytitle("") ylab(, labsize(small))  legend(off) nofill 
graph save "`stick'\My Documents\Research\Paper PID Experiment\Russia\urgr4.gph", replace

graph combine ///
"`stick'\My Documents\Research\Paper PID Experiment\Russia\urgr1.gph" ///
"`stick'\My Documents\Research\Paper PID Experiment\Russia\urgr2.gph" ///
"`stick'\My Documents\Research\Paper PID Experiment\Russia\urgr3.gph" ///
"`stick'\My Documents\Research\Paper PID Experiment\Russia\urgr4.gph", ///
row(2) col(2) graphregion(color(white))
graph export "`stick'\My Documents\Research\Paper PID Experiment\LaTeX\RussiaCriterion1.pdf", as(pdf) replace

drop q40aa0-q5b2
separate dumavoteLDPR, by(pref_close_LDPR)
separate q40aa, by(pref_close_LDPR)
separate q40ab, by(pref_close_LDPR)
separate q5b, by(pref_close_LDPR)

graph bar (mean) dumavoteLDPR? [pweight=qvec], over(pref_close_LDPR, label(angle(0) labsize(small) alternate tick labgap(0)))  graphregion(color(white)) plotregion(lcolor(black)) ///
blabel(bar, format(%9.2f) size(small)) bar(1, color(white) lcolor(black)) bar(2, color(gs12)) bar(3, color(black)) title("1: Duma vote for LDPR") ytitle("") ylab(, labsize(small))  legend(off) nofill
graph save "`stick'\My Documents\Research\Paper PID Experiment\Russia\ldgr1.gph", replace

graph bar (mean) q40aa? [pweight=qvec], over(pref_close_LDPR, label(angle(0) labsize(small) alternate tick labgap(0)))  graphregion(color(white)) plotregion(lcolor(black)) ///
blabel(bar, format(%9.2f) size(small)) bar(1, color(white) lcolor(black)) bar(2, color(gs12)) bar(3, color(black)) title("2: Putin job approval") exclude0 yscale(range(2(.5)4)) ytick(2 2.5 3 3.5 4) ylab(2 2.5 3 3.5 4) ytitle("") ylab(, labsize(small))  legend(off) nofill 
graph save "`stick'\My Documents\Research\Paper PID Experiment\Russia\ldgr2.gph", replace

graph bar (mean) q40ab? [pweight=qvec], over(pref_close_LDPR, label(angle(0) labsize(small) alternate tick labgap(0)))  graphregion(color(white)) plotregion(lcolor(black)) ///
blabel(bar, format(%9.2f) size(small)) bar(1, color(white) lcolor(black)) bar(2, color(gs12)) bar(3, color(black)) title("3: Government approval") exclude0 yscale(range(2(.5)4)) ytick(2 2.5 3 3.5 4) ylab(2 2.5 3 3.5 4) ytitle("") ylab(, labsize(small))  legend(off) nofill 
graph save "`stick'\My Documents\Research\Paper PID Experiment\Russia\ldgr3.gph", replace

graph bar (mean) q5b? [pweight=qvec], over(pref_close_LDPR, label(angle(0) labsize(small) alternate  tick labgap(0)))  graphregion(color(white)) plotregion(lcolor(black)) ///
blabel(bar, format(%9.2f) size(small)) bar(1, color(white) lcolor(black)) bar(2, color(gs12)) bar(3, color(black)) title("4: Medvedev job approval") yscale(range(0(.2)1)) ytick(0 .2 .4 .6 .8 1) ylab(0 .2 .4 .6 .8 1) ytitle("") ylab(, labsize(small))  legend(off) nofill 
graph save "`stick'\My Documents\Research\Paper PID Experiment\Russia\ldgr4.gph", replace

graph combine ///
"`stick'\My Documents\Research\Paper PID Experiment\Russia\ldgr1.gph" ///
"`stick'\My Documents\Research\Paper PID Experiment\Russia\ldgr2.gph" ///
"`stick'\My Documents\Research\Paper PID Experiment\Russia\ldgr3.gph" ///
"`stick'\My Documents\Research\Paper PID Experiment\Russia\ldgr4.gph", ///
row(2) col(2) graphregion(color(white))
graph export "`stick'\My Documents\Research\Paper PID Experiment\LaTeX\RussiaCriterion2.pdf", as(pdf) replace

drop q40aa0-q5b2
separate dumavotecomm, by(pref_close_comm)
separate q40aa, by(pref_close_comm)
separate q40ab, by(pref_close_comm)
separate q5b, by(pref_close_comm)

graph bar (mean) dumavotecomm? [pweight=qvec], over(pref_close_comm, label(angle(0) labsize(small) alternate tick labgap(0)))  graphregion(color(white)) plotregion(lcolor(black)) ///
blabel(bar, format(%9.2f) size(small)) bar(1, color(white) lcolor(black)) bar(2, color(gs12)) bar(3, color(black)) title("1: Duma vote for CPRF") ytitle("") ylab(, labsize(small))  legend(off) nofill
graph save "`stick'\My Documents\Research\Paper PID Experiment\Russia\cpgr1.gph", replace

graph bar (mean) q40aa? [pweight=qvec], over(pref_close_comm, label(angle(0) labsize(small) alternate tick labgap(0)))  graphregion(color(white)) plotregion(lcolor(black)) ///
blabel(bar, format(%9.2f) size(small)) bar(1, color(white) lcolor(black)) bar(2, color(gs12)) bar(3, color(black)) title("2: Putin job approval") exclude0 yscale(range(2(.5)4)) ytick(2 2.5 3 3.5 4) ylab(2 2.5 3 3.5 4) ytitle("") ylab(, labsize(small))  legend(off) nofill 
graph save "`stick'\My Documents\Research\Paper PID Experiment\Russia\cpgr2.gph", replace

graph bar (mean) q40ab? [pweight=qvec], over(pref_close_comm, label(angle(0) labsize(small) alternate tick labgap(0)))  graphregion(color(white)) plotregion(lcolor(black)) ///
blabel(bar, format(%9.2f) size(small)) bar(1, color(white) lcolor(black)) bar(2, color(gs12)) bar(3, color(black)) title("3: Government approval") exclude0 yscale(range(2(.5)4)) ytick(2 2.5 3 3.5 4) ylab(2 2.5 3 3.5 4) ytitle("") ylab(, labsize(small))  legend(off) nofill 
graph save "`stick'\My Documents\Research\Paper PID Experiment\Russia\cpgr3.gph", replace

graph bar (mean) q5b? [pweight=qvec], over(pref_close_comm, label(angle(0) labsize(small) alternate  tick labgap(0)))  graphregion(color(white)) plotregion(lcolor(black)) ///
blabel(bar, format(%9.2f) size(small)) bar(1, color(white) lcolor(black)) bar(2, color(gs12)) bar(3, color(black)) title("4: Medvedev job approval") yscale(range(0(.2)1)) ytick(0 .2 .4 .6 .8 1) ylab(0 .2 .4 .6 .8 1) ytitle("") ylab(, labsize(small))  legend(off) nofill 
graph save "`stick'\My Documents\Research\Paper PID Experiment\Russia\cpgr4.gph", replace

graph combine ///
"`stick'\My Documents\Research\Paper PID Experiment\Russia\cpgr1.gph" ///
"`stick'\My Documents\Research\Paper PID Experiment\Russia\cpgr2.gph" ///
"`stick'\My Documents\Research\Paper PID Experiment\Russia\cpgr3.gph" ///
"`stick'\My Documents\Research\Paper PID Experiment\Russia\cpgr4.gph", ///
row(2) col(2) graphregion(color(white))
graph export "`stick'\My Documents\Research\Paper PID Experiment\LaTeX\RussiaCriterion3.pdf", as(pdf) replace

*VII. IRT MODELS
*Note: I often fed starting values to these IRT models but it never seemed to make a difference. What does make a difference is number of integration points and the integration method.
*More intpoints are more accurate (Ayala 2009, p. 75 and 104), and ghermite is not trustworthy (see "semintro12" Stata manual, p. 6). Models using ghermite would often converge but were very unstable/sensitive and often nonsensical SEs. 
*mcaghermite produced stable results repeatedly, although slow. mvaghermite also stable and trustworthy, but slightly less likely to converge
*Small parties are more challenging to estimate because of skew (Ayala 2009, 104), so I did these with 60 intpoints

	*1: UR
svy: irt grm prefexp_ur prefimp_ur identity_ur close_ur dumavote_ur ft_ur , intpoints(30) difficult intmethod(mcaghermite) 
test _b[prefexp_ur:Theta]=_b[identity_ur:Theta]
test _b[prefexp_ur:Theta]=_b[close_ur:Theta]
test _b[prefimp_ur:Theta]=_b[identity_ur:Theta]
test _b[prefimp_ur:Theta]=_b[close_ur:Theta]
predict thetaur, latent
summ thetaur

irtgraph icc (ft_ur, lcolor(gs14) lwidth(vthin) lpattern(dash))  (dumavote_ur, lcolor(black) lwidth(medium) lpattern(dash)) (close_ur identity_ur prefexp_ur prefimp_ur, lcolor(black) lwidth(medthick)), ///
addplot((scatteri .4 .27 "Duma Vote", msymbol(i) mlabpos(0) mlabangle(74) mlabcolor(black) mlabsize(vsmall)) ///
(scatteri .5 .62 "Close({it:P{superscript:0}N{superscript:1}})", msymbol(i) mlabpos(0) mlabangle(69) mlabcolor(black) mlabsize(small)) ///
(scatteri .4 0 "Prefer({it:P{superscript:0}N{superscript:0}})", msymbol(i) mlabpos(0) mlabangle(73) mlabcolor(black) mlabsize(small)) ///
(scatteri .86 .36 "Prefer({it:P{superscript:1}N{superscript:0}})", msymbol(i) mlabpos(0) mlabangle(72) mlabcolor(black) mlabsize(small)) /// 
(scatteri .86 .84 "Belong({it:P{superscript:1}N{superscript:1}})", msymbol(i) mlabpos(0) mlabangle(47) mlabcolor(black) mlabsize(small))) ///
bcc range(-1.40 1.47) legend(off) graphregion(color(white)) plotregion(lstyle(yxline) lcolor(black)) b1title("{it: θ{subscript:UR}}: Strength of United Russia Partisanship") xtitle("") ytitle("{it:Pr}({it:x{subscript:j•UR}}|{it: θ{subscript:UR}})") title("")  xtick(-2(.5)2) xlabel(-2(1)2)
*graph export "F:\My Documents\Research\Paper PID Experiment\LaTeX\URIRT.pdf", as(pdf) replace

polychoric thetaur prefexp_ur prefimp_ur identity_ur close_ur dumavote_ur ft_ur, pw verbose

	*2: LDPR
set more off
*intpoints of 60 more stable here for small parties
svy: irt grm prefexp_LDPR prefimp_LDPR identity_LDPR close_LDPR dumavote_LDPR ft_LDPR , intpoints(60) difficult intmethod(mcaghermite)
test _b[prefexp_LDPR:Theta]=_b[identity_LDPR:Theta]
test _b[prefexp_LDPR:Theta]=_b[close_LDPR:Theta]
test _b[prefimp_LDPR:Theta]=_b[identity_LDPR:Theta]
test _b[prefimp_LDPR:Theta]=_b[close_LDPR:Theta]
predict thetaLDPR, latent
summ thetaLDPR

irtgraph icc (ft_LDPR, lcolor(gs14) lwidth(vthin) lpattern(dash))  (dumavote_LDPR, lcolor(black) lwidth(medium) lpattern(dash)) (close_LDPR identity_LDPR prefexp_LDPR prefimp_LDPR, lcolor(black) lwidth(medthick)), ///
addplot((scatteri .85 1.55 "Prefer({it:P{superscript:1}N{superscript:0}})", msymbol(i) mlabpos(0) mlabangle(75) mlabcolor(black) mlabsize(small)) ///
(scatteri .5 1.65 "Duma Vote", msymbol(i) mlabpos(0) mlabangle(81) mlabcolor(black) mlabsize(vsmall)) ///
(scatteri .5 1.84 "Close({it:P{superscript:0}N{superscript:1}})", msymbol(i) mlabpos(0) mlabangle(80) mlabcolor(black) mlabsize(small)) ///
(scatteri .5 1.41 "Prefer({it:P{superscript:0}N{superscript:0}})", msymbol(i) mlabpos(0) mlabangle(81) mlabcolor(black) mlabsize(small)) /// 
(scatteri .8 2.1 "Belong({it:P{superscript:1}N{superscript:1}})", msymbol(i) mlabpos(0) mlabangle(77) mlabcolor(black) mlabsize(small))) ///
bcc range(-.98 2.32) legend(off) graphregion(color(white)) plotregion(lstyle(yxline) lcolor(black)) b1title("{it: θ{subscript:LDPR}}: Strength of LDPR Partisanship") xtitle("") ytitle("{it:Pr}({it:x{subscript:j•LDPR}}|{it: θ{subscript:LDPR}})")  title("") xtick(-2(.5)2.5) xlabel(-2(1)2.5)
*graph export "F:\My Documents\Research\Paper PID Experiment\LaTeX\LDPRIRT.pdf", as(pdf) replace

polychoric thetaLDPR prefexp_LDPR prefimp_LDPR identity_LDPR close_LDPR dumavote_LDPR ft_LDPR, pw verbose

	*3: COMM
set more off
display "$S_TIME  $S_DATE"

irt grm pref_comm identity_comm close_comm dumavote_comm ft_comm , intpoints(60) difficult intmethod(mcaghermite)

test _b[pref_comm:Theta]=_b[identity_comm:Theta]
test _b[pref_comm:Theta]=_b[close_comm:Theta]
predict thetacomm, latent ebmodes
summ thetacomm

irtgraph icc (ft_comm, lcolor(gs14) lwidth(vthin) lpattern(dash))  (dumavote_comm, lcolor(black) lwidth(medium) lpattern(dash)) (close_comm identity_comm pref_comm, lcolor(black) lwidth(medthick)), ///
addplot((scatteri .5 1.7 "Close({it:P{superscript:0}N{superscript:1}})", msymbol(i) mlabpos(0) mlabangle(73) mlabcolor(black) mlabsize(small)) ///
(scatteri .8 1.56 "Duma Vote", msymbol(i) mlabpos(0) mlabangle(77) mlabcolor(black) mlabsize(vsmall)) ///
(scatteri .5 1.31 "Prefer({it:N{superscript:0}})", msymbol(i) mlabpos(0) mlabangle(82) mlabcolor(black) mlabsize(small)) /// 
(scatteri .85 1.85 "Belong({it:P{superscript:1}N{superscript:1}})", msymbol(i) mlabpos(0) mlabangle(60) mlabcolor(black) mlabsize(small))) ///
bcc range(-1.11 1.98) legend(off) graphregion(color(white)) plotregion(lstyle(yxline) lcolor(black)) b1title("{it: θ{subscript:CPRF}}: Strength of CPRF Partisanship") xtitle("") ytitle("{it:Pr}({it:x{subscript:j•CPRF}}|{it: θ{subscript:CPRF}})")  title("") xtick(-2(.5)2) xlabel(-2(1)2) 
*graph export "F:\My Documents\Research\Paper PID Experiment\LaTeX\CPRFIRT.pdf", as(pdf) replace

polychoric thetacomm pref_comm identity_comm close_comm dumavote_comm ft_comm , pw verbose 

display "$S_TIME  $S_DATE"

*Item-rest correlations
*1: UR
capture drop thetaur
svy: irt grm prefimp_ur identity_ur close_ur dumavote_ur ft_ur , intpoints(30) difficult intmethod(mcaghermite) 
predict thetaur, latent
polychoric thetaur prefexp_ur prefimp_ur identity_ur close_ur, pw verbose

drop thetaur
svy: irt grm prefexp_ur identity_ur close_ur dumavote_ur ft_ur , intpoints(30) difficult intmethod(mcaghermite) 
predict thetaur, latent
polychoric thetaur prefexp_ur prefimp_ur identity_ur close_ur, pw verbose

drop thetaur
svy: irt grm prefexp_ur prefimp_ur close_ur dumavote_ur ft_ur , intpoints(30) difficult intmethod(mcaghermite) 
predict thetaur, latent
polychoric thetaur prefexp_ur prefimp_ur identity_ur close_ur, pw verbose

/*
drop thetaur
svy: irt grm prefexp_ur prefimp_ur identity_ur dumavote_ur ft_ur , intpoints(60) difficult intmethod(mcaghermite) 
predict thetaur, latent
polychoric thetaur prefexp_ur prefimp_ur identity_ur close_ur, pw verbose
*/

*2: LDPR
capture drop thetaLDPR
svy: irt grm prefimp_LDPR identity_LDPR close_LDPR dumavote_LDPR ft_LDPR , intpoints(60) difficult intmethod(mcaghermite)
predict thetaLDPR, latent
polychoric thetaLDPR prefexp_LDPR prefimp_LDPR identity_LDPR close_LDPR , pw verbose

drop thetaLDPR
svy: irt grm prefexp_LDPR identity_LDPR close_LDPR dumavote_LDPR ft_LDPR , intpoints(60) difficult intmethod(mcaghermite)
predict thetaLDPR, latent ebmodes
polychoric thetaLDPR prefexp_LDPR prefimp_LDPR identity_LDPR close_LDPR , pw verbose

drop thetaLDPR
svy: irt grm prefexp_LDPR prefimp_LDPR close_LDPR dumavote_LDPR ft_LDPR , intpoints(60) difficult intmethod(mcaghermite)
predict thetaLDPR, latent
polychoric thetaLDPR prefexp_LDPR prefimp_LDPR identity_LDPR close_LDPR , pw verbose

/*
drop thetaLDPR
svy: irt grm prefexp_LDPR prefimp_LDPR identity_LDPR dumavote_LDPR ft_LDPR , intpoints(60) difficult intmethod(mcaghermite)
predict thetaLDPR, latent
polychoric thetaLDPR prefexp_LDPR prefimp_LDPR identity_LDPR close_LDPR , pw verbose
*/

*3:COMM
capture drop thetacomm
irt grm identity_comm close_comm dumavote_comm ft_comm , intpoints(60) difficult intmethod(mcaghermite)
predict thetacomm, latent ebmodes
polychoric thetacomm pref_comm identity_comm close_comm dumavote_comm ft_comm , pw verbose 

drop thetacomm
irt grm pref_comm close_comm dumavote_comm ft_comm , intpoints(60) difficult intmethod(mcaghermite)
predict thetacomm, latent ebmodes
polychoric thetacomm pref_comm identity_comm close_comm dumavote_comm ft_comm , pw verbose 

/*
capture drop thetacomm
irt grm pref_comm identity_comm dumavote_comm ft_comm , intpoints(60) difficult intmethod(mcaghermite)
predict thetacomm, latent ebmodes
polychoric thetacomm pref_comm identity_comm close_comm dumavote_comm ft_comm , pw verbose 
*/

log close
